package com.gao.interceptordemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.naming.spi.Resolver;
import java.util.Locale;

/**
 * 自定义功能,只需要写这个组件.交给SpringBoot,会自动装配
 * 扩展SpringMVC DispatcherServlet
 * @author gaofeng
 * date 2021年09月27日 22:03
 */
@Configuration
//@EnableWebMvc
public class MyMvcController implements WebMvcConfigurer {
    /**
     *  public interface ViewResolver --实现了试图解析器的类
     */
    @Bean
    public ViewResolver myViewResolver() {
        return new MyViewResolver() ;
    }

    /**
     *
     * @author gaofeng
     * @date  2022/6/28 20:00
     */
    public static class MyViewResolver implements ViewResolver {
        @Override
        public View resolveViewName(String viewName, Locale locale) {
            return null;
        }
    }

    @Override
    public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {
        viewControllerRegistry.addViewController("/gao").setViewName("a");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/*").excludePathPatterns("静态资源") ;
    }
}
